<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品管理</title> <#include "/WEB-INF/content/module-index.html">
<script type="text/javascript">
var typeTree=[
	<#list map.typeTree as item>
		{"id":"${item.id}","text":"${item.text}","children":[
			<#list item.children as ite>
				{"id":"${ite.id}","text":"${ite.text}"}<#if ite_has_next>,</#if>
			</#list>
		]}<#if item_has_next>,</#if>
	</#list>
];

var products={
		<#list map.products as item>
			"_${item.pid}":"${item.productname}"<#if item_has_next>,</#if>
		</#list>
	};
$(function(){
	$("#search").click(function(){
		var productname=$("#productname").val();
		var parent=$("#parent").combobox("getValue");
		var ptid=$("#ptid").combobox("getValue");
		var leftCreateTime=$("#leftCreateTime").datebox("getValue");
		var rightCreateTime=$("#rightCreateTime").datebox("getValue");
		$("#grid").datagrid("reload",{"_productname":productname,"ptid":ptid,
		"parent":parent,"leftCreateTime":leftCreateTime,"rightCreateTime":rightCreateTime});		
	});	
	$("#clear").click(function(){
		$("#productname").val("");
		$("#pid").val("");
		$("#parent").combobox("setValue","");
		$("#ptid").combobox("setValue","");
		$("#leftCreateTime").datebox("setValue","");
		$("#rightCreateTime").datebox("setValue","");
	});
  	$("#parent").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
  		data:typeTree,
  		onChange:function(data){
  			$("#ptid").combobox('setValue','');
  			for(var i in typeTree){
  				if(typeTree[i].id==data){
  					$("#ptid").combobox('loadData',typeTree[i].children);
  				}
  			}
  		}
  	});	
	$("#ptid").combobox({
	  		valueField : 'id',
	  		textField : 'text',
	  		editable:false,
	        panelHeight:'auto'
		});
});
function productFormatter(value,rowData,rowIndex){
	if(value=="0"){
		return "上架";
	}else
		if(value=="1"){
			return "下架";
		}else{
			return "未设置";
		}
}
function comFormatter(value,rowData,rowIndex){
	if(value=="0"){
		return "是";
	}else
		if(value=="1"){
			return "否";
		}else{
			return "未设置";
		}
}

function typeFormatter(value,rowData,rowIndex){
	if(value==0){
		return "android";
	}else
		if(value==1){
			return "ios";
		}else
			if(value==2){
				return "所有";
			}else{
				return "未知";
			}
}

function idFormatter(value,rowData,rowIndex){
	return rowData.ppid;
}

function nameFormatter(value,rowData,rowIndex){
	return eval("products._"+rowData.pid);
}

function handleFormatter(value,rowData,rowIndex){
	return '<a href="javascript:uploadImg(\''+rowData.pid+'\')">标签管理</a>';
}

function uploadImg(pid){
	top.openModule("product_sale-tags","商品标签管理","product/sale/tags/index?pid="+pid);
}
</script>
<style>
a.btn-border{
	border: 1px solid #ccc;
}
</style>
</head>
<body>
<body class="easyui-layout">
	<div region="center" style="padding: 5px; background:#eee;">
		<div id="toolbar">
 			<label>库存商品:</label><input id="productname"/>
			<label>商品分类:</label><input id="parent"><input id="ptid"/>
			<label>上架时间:</label><input id="leftCreateTime" class="easyui-datebox"/>
			<label>至:</label><input id="rightCreateTime" class="easyui-datebox"/>						
			<a id="search" class="easyui-linkbutton" icon="icon-search" style="border: 1px solid #ccc" plain="true">搜索</a>
			<a id="clear" class="easyui-linkbutton" icon="icon-no" style="border: 1px solid #ccc" plain="true">清空</a><br/>
			<@auth code="product:sale:new">
				<a id="new" class="easyui-linkbutton" onclick="javascript:add();" icon="icon-add" style="border: 1px solid #ccc" plain="true">上架</a>
			</@auth>
			<@auth code="product:sale:*:edit">
				<a id="edit" class="easyui-linkbutton" onclick="javascript:edit();" icon="icon-edit" style="border: 1px solid #ccc" plain="true">编辑</a>
			</@auth>
		</div>
		<table id="grid" class="easyui-datagrid" url="query" idField="ppid" align="center" rownumbers="true" striped="true" fitColumns="true" fit="true" pagination="true" singleSelect="true" toolbar="#toolbar">
			<thead>
				<tr>
					<th field="handler" width="10" formatter="idFormatter">销售ID</th>
					<th field="pid" width="10">商品编号</th>
					<th field="productname" width="10">销售名称</th>
					<th field="ppid" width="10" formatter="nameFormatter">库存商品</th>
					<th field="productprice" width="5">真实交易价格</th>
					<th field="productshowprice" width="5">显示价格</th>
					<th field="os" width="5" formatter="typeFormatter">平台</th>
					<th field="show_order" width="5">展示顺序</th>
					<th field="productuptime" width="10">上架时间</th>
					<th field="productdowntime" width="10">下架时间</th>
					<th field="createtime" width="10">创建时间</th>
					<th field="creator" width="5">创建人</th>
					<@auth code="product:sale:tags:index">
					<th field="handle" width="10" formatter="handleFormatter" align="center">操作</th>
					</@auth>
				</tr>
			</thead>
		</table>
	</div>
</body>
</body>

</html>